package net.huashitong.supervision.AppNew.appService;

import com.sirdc.modules.sys.entity.SysUser;
import com.sirdc.modules.sys.service.SysUserService;
import com.sirdc.modules.utils.ObjectUtils;
import net.huashitong.supervision.insideDuCha.dao.InsideMainTaskDao;
import net.huashitong.supervision.insideDuCha.dao.InsideSubTaskDao;
import net.huashitong.supervision.insideDuCha.dao.InsideUserTaskDao;
import net.huashitong.supervision.insideDuCha.entity.InsideMainTaskEntity;
import net.huashitong.supervision.insideDuCha.entity.InsideSubTaskEntity;
import net.huashitong.supervision.insideDuCha.entity.InsideUserTaskEntity;
import net.huashitong.supervision.insideDuCha.filter.InsideUserTaskFilter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;

@Service
public class AppInsideService {

    @Autowired
    private InsideMainTaskDao maindao;

    @Autowired
    private InsideSubTaskDao subdao;

    @Autowired
    private InsideUserTaskDao usertaskdao;
    @Autowired
    private SysUserService userService;





    public List<InsideUserTaskFilter> getTaskLists(InsideUserTaskFilter filter) {

//        InsideUserTaskFilter usertask = new InsideUserTaskFilter();



        List<InsideUserTaskEntity> userTasks = usertaskdao.getUserTasks(filter);

        List<InsideUserTaskFilter> list = new ArrayList<>();
        for (InsideUserTaskEntity userTask : userTasks) {
            InsideSubTaskEntity subTask = subdao.getById(userTask.getSubTaskId());
            InsideMainTaskEntity maintask = maindao.getById(userTask.getMainTaskId());
            InsideUserTaskFilter data = new InsideUserTaskFilter();

            BeanUtils.copyProperties(userTask,data);
            data.setSubName(subTask.getSubTaskName());
            data.setMainName(maintask.getTaskName());
            data.setCreateDate(data.getCreateDate()+" "+data.getCreateTime());
            String createUser = userTask.getCreateUser();
            SysUser userEntity = userService.getById(createUser);
            SysUser chengbanren = userService.getById(userTask.getUserId());
            if(ObjectUtils.isNotBlank(userEntity))
            {
                data.setCreateUserName(userEntity.getName());
            }
            if(ObjectUtils.isNotBlank(chengbanren))
            {
                data.setUserName(chengbanren.getName());
            }
            data.setRemindDate(data.getRemindDate()+" "+"00:00:00");
            list.add(data);

        }

        return list;

    }




}
